package com.nstar.orderexpress.view
{
	import mx.containers.HBox;
	import com.nstar.base.controls.AnimatedTileList;
	import mx.controls.VSlider;
	import mx.events.FlexEvent;
	import mx.events.SliderEvent;
	import com.nstar.orderexpress.model.Model;
	import com.nstar.base.util.Logger;
	import mx.events.DragEvent;
	import mx.managers.DragManager;
	import flash.display.DisplayObject;
	import mx.controls.Alert;
	import mx.controls.Button;
	import flash.events.MouseEvent;
	import mx.controls.HSlider;
	

	public class FilterClass extends HBox
	{
		public var atlMenuList:AnimatedTileList;
		public var filterSlider:HSlider;
		
		private var model:Model = Model.getInstance();
		private var logger:Logger = Logger.getInstance();
		
		public function FilterClass()
		{
			//TODO: implement function
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,init);
		}
		
		private function init(event:FlexEvent):void{
			this.addEventListener(DragEvent.DRAG_ENTER,dragEnterHandler);
			this.addEventListener(DragEvent.DRAG_DROP,dropDropHandler);
			filterSlider.addEventListener(SliderEvent.CHANGE,changeHandler);
		}
		
		
		//接收拖动
		private function dragEnterHandler(event:DragEvent):void{
			if (event.dragSource.hasFormat("myorder")){
				DragManager.acceptDragDrop(HBox(event.target));	
			}
		}
		
		//接收来自购物车中的拖入的对象
		private function dropDropHandler(event:DragEvent):void{
			//删除我的订单中的数据
			if (event.dragSource.hasFormat("myorder")){
				var object:DisplayObject = DisplayObject(event.dragSource.dataForFormat("myorder"));
				model.mainApp.mainView.shoppingCartView.orderMenuList.removeChild(object);
			}
			
		}
		
		//条件过滤回调方法
		private function filterCallback(item:Object):Boolean{
			return item.orderMenu.price<filterSlider.value;
		}
		
		//数据过滤
		private function changeHandler(event:SliderEvent):void{
			model.mainApp.mainView.filterView.atlMenuList.filter(filterCallback,true);
		}
	}
}